package com.iceGame;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.GLCommon;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector3;

public class ScoreMenuScreen implements Screen{

	OrthographicCamera guiCam;
	SpriteBatch batcher;
	Game game;
	Vector3 touchPoint;
	Rectangle backButton;
	Rectangle nextLevelButton;
	Rectangle restartLevelButton;
	int width = 800;
	int height = 480;
	PhysicsWorld world;
	
	public ScoreMenuScreen (Game game, PhysicsWorld world){
		this.game=game;	
		this.world = world;
		batcher = new SpriteBatch();
		guiCam = new OrthographicCamera(width,height);		
		guiCam.position.set(width / 2, height / 2, 0);
		touchPoint = new Vector3();	
		backButton = new Rectangle(260,150,65,55);
		restartLevelButton = new Rectangle(370,150,65,55);
		nextLevelButton = new Rectangle(480,150,65,55);
	}
	
	@Override
	public void dispose() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void hide() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void render(float deltaTime) {
		update(deltaTime);
		GLCommon gl = Gdx.gl;
		//gl.glClearColor(1, 0, 0, 1);
		//gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		guiCam.update();
		batcher.setProjectionMatrix(guiCam.combined);	
		batcher.enableBlending();
		batcher.begin();
		batcher.draw(Assets.ScoreMenuScreen, 250,145, 300, 190);		
		for(int i=0; i<world.numOfStars; i++){
			batcher.draw(Assets.bigScoreStar, 274+100*i, 202, 55, 65);
		}
		batcher.disableBlending();
		batcher.end();			
	}

	private void update(float deltaTime) {
		if (Gdx.input.justTouched()) {
			guiCam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
			if (OverlapTester.pointInRectangle(backButton, touchPoint.x, touchPoint.y)) {
				if (Settings.soundEnabled)
					Assets.buttonPressSound.play();
				game.setScreen(new LevelSelectionScreen(game));
				this.dispose();
			}
			if (OverlapTester.pointInRectangle(restartLevelButton, touchPoint.x, touchPoint.y)) {
				if (Settings.soundEnabled)
					Assets.buttonPressSound.play();
				game.setScreen(new GameScreen(game, world.currentLevel.levelNumber));
				this.dispose();
			}
			if (OverlapTester.pointInRectangle(nextLevelButton, touchPoint.x, touchPoint.y)) {
				if (Settings.soundEnabled)
					Assets.buttonPressSound.play();
				if(this.world.currentLevel.levelNumber < this.world.topLevel ){
					game.setScreen(new GameScreen(game, world.currentLevel.levelNumber +1));
				}
				else{
					game.setScreen(new LevelSelectionScreen(game));
				}
				this.dispose();
			}
		}
		
	}

	@Override
	public void resize(int arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void show() {
		// TODO Auto-generated method stub
		
	}
	

}
